import { defineAsyncComponent } from 'vue'
const regCom = (res, imageParams = null) => {
  return defineAsyncComponent(() => {
    let a = new Promise((resolve, reject) => {
      let reg = /<template>([\s|\S]*)<\/template>[\s|\S]*export default([\s|\S]*)<\/script>/g
      let b = reg.exec(res)

      if (!b) {
        reject({
          template: '<div>无效的组件</div>',
        })
      }
      let obj = eval('(' + b[2] + ')')
      if (imageParams) {
        obj.data = () => {
          console.log('图片文本转data: ', imageParams)
          return {
            imageParams,
          }
        }
      }
      console.log('转换的组件', obj)
      resolve({
        template: b[1],
        props: obj.props,
        data: obj.data,
      })
    })
    return a
  })
}
export default regCom
